//
//  AppDelegate.m
//  YiShangPin
//
//  Created by yishangpin2 on 15/3/6.
//  Copyright (c) 2015年 yishangpin2. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate (){
    UIStoryboard *storyboard;

}

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    _waterfall = [[Waterfall alloc] init];
    _detailsDic = [[NSMutableDictionary alloc] init];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    //    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
    
    self.window.backgroundColor = [UIColor whiteColor];    //获取屏幕宽度与高度
   
    CGRect rect = [[UIScreen mainScreen] bounds];
    CGSize size = rect.size;
    _width = size.width;
    _height = size.height;
    NSLog(@"屏幕宽度：%f,屏幕高度：%f",_width,_height);
    
    //初始化本地收藏数组
    _CollectArray = [NSMutableArray array];
    //初始化本地购物车数组
    _ShoppingArray = [NSMutableArray array];
    
    [self SetRootViewRegister];
    
    //连接数据库的地址
    _path_URL = @"http://192.168.0.88:8888/thinkphp_3.2.3_full/index.php/Home/";
    
    return YES;
}

#pragma mark - 注册作为window根控制器
- (void)SetRootViewRegister{
    
    UINavigationController *registerCV = [storyboard instantiateViewControllerWithIdentifier:@"register"];
    self.window.rootViewController = registerCV;
    [self.window makeKeyAndVisible];
    
}

#pragma mark - 侧滑作为window根控制器
- (void)SetRootViewsideview{
    
    SideslipMenuViewController *rightViewController=[storyboard instantiateViewControllerWithIdentifier:@"SideslipMenuViewController"];
    
    _sideViewController=[[YRSideViewController alloc]initWithNibName:nil bundle:nil];
    _sideViewController.rootViewController=[storyboard instantiateInitialViewController];
    
    _sideViewController.rightViewController=rightViewController;
    
    
    _sideViewController.rightViewShowWidth = _width/3;
    
    
    self.window.rootViewController=_sideViewController;
    
    
    [self.window makeKeyAndVisible];
    
    //统一设置导航栏的颜色
    
    
    for (int i = 0; i<5 ; i++) {
        UINavigationController * navigation = _sideViewController.rootViewController.viewControllers[i];
        navigation.navigationBar.barTintColor = [UIColor colorWithRed:90.f/255 green:170.f/255 blue:220.f/255 alpha:0.7];
        //修改title的颜色
        NSDictionary * dict=[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
        navigation.navigationBar.titleTextAttributes = dict;
        //返回按钮的颜色
        navigation.navigationBar.barStyle = UIStatusBarStyleDefault;
        [navigation.navigationBar setTintColor:[UIColor whiteColor]];
    }



}

- (UINavigationController *)CurrentViewController{
    
    UINavigationController *currentViewController = _sideViewController.rootViewController.viewControllers[_sideViewController.rootViewController.selectedIndex];
    
    return currentViewController;

}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
